# Concave
# Copyright (C) 2012 Daniel Malmqvist
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import pygame
import random
from pygame.locals import *

# A simple class for holding a pixel
class Snow():
    def __init__(self,x,y, speed):
        self.x = x
        self.y = y
        self.speed = random.randint(1,5)
        self.color = (random.randint(0,255), random.randint(0,255), random.randint(0,255))
    def update(self):
        self.x -= self.speed
        if self.x < 0:
            self.x = 640 + self.speed
    def getPos(self):
        return (self.x, self.y)

# Holds a text block
class TextBla():
    def __init__(self,x,y, speed, text, font, restartAtX):
        self.x = x
        self.y = y
        self.speed = speed
        self.text = text
        self.font = font
        self.restartAtX = restartAtX
        
    def update(self):
        self.x -= self.speed
        if self.x < -600:
            self.x = self.restartAtX
            if self.y > 95:
                self.y = random.randint(130, 460)
            
    def getPos(self):
        return (self.x, self.y)
    def getImage(self):
        return self.font.render(self.text, 1, (255,255,255))


# Shows the credits to the game
def showCredits():
    pygame.init()
    pygame.display.set_caption("Concave")
    
    fontBigger = pygame.font.Font(None, 60)
    fontBig = pygame.font.Font(None, 24)
    
    screen = pygame.display.set_mode((640, 480))
    
    clock = pygame.time.Clock()
    
    
    # Create all the text blocks
    credit = ["Concave", "   Big thanks goes out to:", "OpenGameArt.org", "Bart Kelsey", 
              "Wulax", "Mumu", "Lanea Zimmerman (AKA Sharm)", 
              "Stephen Challener (AKA Redshrike)", "Brandon", "Stephen Challener", "Juan M. Rodriguez",
              "Nelson James Gatlin", "Johnathan Roatch", "daneeklu & gr3yh47"]
    textCredit = []
    for i in range (0,len(credit)):
        if i <= 1:
            if i == 0:
                textCredit.append(TextBla(640, 20, 4, credit[i], fontBigger, 640+len(credit)*200))
            else:
                textCredit.append(TextBla(640, 90, 4, credit[i], fontBigger, 640+len(credit)*200))
        else:
            textCredit.append(TextBla(1000+i*200, random.randint(130,460), 4, credit[i], fontBig, 640+len(credit)*200))
            
        
    # Create some snow pixels at random places
    snow = []
    for apa in range (0,4000):
        snow.append(Snow(random.randint(0,640), random.randint(0,480), apa%2 + 1))
    
    showCredits = True
    
    while (showCredits):
        # Handle events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                showCredits = False
            elif (event.type == KEYDOWN):
                showCredits = False
            elif (event.type == MOUSEBUTTONDOWN):
                showCredits = False
        
        # Update positions for snow and texts
        for apa in snow:
            apa.update()
        for apa in textCredit:
            apa.update()

        # Background color
        screen.fill((0x32, 0x21, 0x25))
        
        # Display snow
        for apa in snow:
            screen.set_at(apa.getPos(), apa.color)
        
        # Display texts
        for apa in textCredit:
            screen.blit(apa.getImage(), apa.getPos())
        
        # Draw everything
        pygame.display.flip()
        
        # Hold for 1/60 sec
        clock.tick(60)